package com.web.dao;

import com.github.pagehelper.Page;
import com.web.controller.web.WebFeedBackController;
import com.web.dto.FeedbackDto;
import com.web.entity.Feedback;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

/**
 * @author FDjavaone
 */
public interface FeedbackMapper {


    @Delete({
            "delete from t_feedback",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_feedback (m_id, content, ",
            " create_time, modify_time)",
            " values (#{mId,jdbcType=BIGINT}, #{content,jdbcType=VARCHAR}, ",
            " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(Feedback record);

    @InsertProvider(type = FeedbackSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertSelective(Feedback record);


    @Select({
            "select",
            " id, m_id, content, create_time, modify_time",
            " from t_feedback",
            " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Feedback selectByPrimaryKey(Long id);


    @UpdateProvider(type = FeedbackSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Feedback record);

    @Update({
            "update t_feedback",
            " set m_id = #{mId,jdbcType=BIGINT},",
            " content = #{content,jdbcType=VARCHAR},",
            " create_time = #{createTime,jdbcType=TIMESTAMP},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Feedback record);


    @SelectProvider(type = FeedbackSqlProvider.class, method = "selectAllFeedbacks")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR)
    })
    Page<FeedbackDto> selectAllFeedbacks(WebFeedBackController.FeedbackColumns feedbackColumns);
}